<?php
/**
 * @name		
 * @author		C. Hazekamp
 * @copyright	C. Hazekamp
 * @version     2.0.0
 * @date   		18-6-2012 15:42:20
 * @access		private
 * @filesource	cms/media/default.php
 * @package     ObbyCMS 2.0
 */

if (!defined('PUBLIC_HTML'))
{
	exit;
}

// Type
$type_id = (isset($_GET['type'])) ? $_GET['type'] : 0;

// Get Internals
$get_internals =	"
					SELECT	*
					FROM	" . TABLE_MEDIA_TYPES . "
					WHERE	medt_source = :medt_source	
					";
$database->query($get_internals);
$database->bind(':medt_source', MEDIA_INTERNAL);
foreach ($database->resultSet() as $row_media_types)
{
	$tpl->zone('int', array(
		'TITLE'	=> $row_media_types['medt_title'],
		'LINK'	=> '?p=media&type=' . $row_media_types['medt_id']
	));
}

// Get Externals
$get_externals =	"
					SELECT		*
					FROM		" . TABLE_MEDIA_TYPES . "
					WHERE		medt_source = :medt_source
					ORDER BY	medt_title
					ASC
					";
$database->query($get_externals);
$database->bind(':medt_source', MEDIA_EXTERNAL);
foreach ($database->resultSet() as $row_media_types)
{
	$tpl->zone('ext', array(
		'TITLE'	=> $row_media_types['medt_title'],
		'LINK'	=> '?p=media&type=' . $row_media_types['medt_id']
	));
}

// Get Media
$where_type = ($type_id == 0) ? '' : ' WHERE med_type = :med_type';
$get_media		 =	"
					SELECT	m.*,t.*
					FROM	" . TABLE_MEDIA . " m
					JOIN	" . TABLE_MEDIA_TYPES . " t
					ON		(t.medt_id = m.med_type)
					" . $where_type;
$database->query($get_media);
if ($type_id > 0)
{
	$database->bind(':med_type', $type_id);
}
foreach ($database->resultSet() as $row_media)
{
	$tpl->zone('media', array(
		'TITLE'		=> $row_media['med_title'],
		'TYPE'		=> $row_media['medt_title'],
		'VIEW'		=> 'media/content/' . $row_media['med_file'],
		'EDIT'		=> '?p=media&act=edit&id=' . $row_media['med_id'],
		'DELETE'	=> '?p=media&act=delete&id=' . $row_media['med_id']
	));
}

?>